import cv2
import numpy as np

# 读取图像
file = "../../res/121.jpg"
img = cv2.imread(file, 0)

# Otsu's 二值化
ret, thresh3 = cv2.threshold(img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)

# 显示结果
cv2.imshow('Otsu\'s Threshold', thresh3)
cv2.waitKey(0)
cv2.destroyAllWindows()